import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_massage/common_lib/http/index.dart';
import 'package:flutter_massage/common_lib/index.dart';
import 'package:flutter_massage/common_lib/utils/method_channel.dart';
import 'package:flutter_massage/service/index.dart';
import 'package:flutter_massage/sqlite/db_implements.dart';
import 'package:flutter_massage/sqlite/db_manager.dart';
import 'package:flutter_massage/values/index.dart';
import 'package:get/get.dart';

class Global {
  static Future init() async {
    WidgetsFlutterBinding.ensureInitialized();

    setSystemUi();

    /// 初始化工具类
    await Storage().init();
    Loading();

    ///初始化db
    DbManager().init(dbImplements: DbImplements());

    ///获取apns令牌
    XydMethodChannel.nativeCallFlutter((call) async {
      if (call.method == 'deviceToken') {
        ConstantValues().deviceToken = call.arguments;
      }
    });

    /// 初始化网络请求
    await CommonNet().init(LinkNetSkeleton(), CoreNetBuilder());

    /// 初始化服务(如果不同服务需要互相依赖，注意注入的顺序！！！)
    Get.put<LocationService>(LocationService());
    Get.put<XydUserService>(XydUserService());
    Get.put<JsonService>(JsonService());
    Get.put<GetStorageService>(GetStorageService());
  }

  // 系统样式
  static void setSystemUi() {
    if (GetPlatform.isMobile) {
      // 屏幕方向 竖直上
      SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
      // 透明状态栏
      // SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
      //   statusBarColor: Colors.transparent, // transparent status bar
      // ));
    }

    if (GetPlatform.isAndroid) {
      // 去除顶部系统下拉和底部系统按键
      // SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
      // 去掉底部系统按键
      // SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
      //     overlays: [SystemUiOverlay.bottom]);

      // 自定义样式
      SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
        // 顶部状态栏颜色
        // statusBarColor: Colors.transparent,
        // 该属性仅用于 iOS 设备顶部状态栏亮度
        // statusBarBrightness: Brightness.light,
        // 顶部状态栏图标的亮度
        // statusBarIconBrightness: Brightness.light,

        // 底部状态栏与主内容分割线颜色
        systemNavigationBarDividerColor: Colors.transparent,
        // 底部状态栏颜色
        systemNavigationBarColor: Colors.white,
        // 底部状态栏图标样式
        systemNavigationBarIconBrightness: Brightness.dark,
      );
      SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
    }
  }
}
